﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using DunLibrary.Dun;
using DunSilverlight.Comm;

namespace DunSilverlight.Views
{
    public partial class ReceiveTypeOfCallForm : UserControl
    {
       private ReceiveTypeOfCall reciveType;
       public ReceiveTypeOfCallForm(ReceiveTypeOfCall reciveType)
        {
            this.reciveType = reciveType;
            InitializeComponent();
            Loaded += new RoutedEventHandler(ReciveTypeOfCallForm_Loaded);
        }
        void ReciveTypeOfCallForm_Loaded(object sender, RoutedEventArgs e)
        {
            DataContext = reciveType;
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtName.Text.Trim()))
                {
                    Tools.ShowMessage("名称不能为空!", "", false);
                    return;
                }

                if (string.IsNullOrEmpty(txtNumber.Text.Trim()))
                {
                    Tools.ShowMessage("编号不能为空!", "", false);
                    return;
                }

                ReceiveTypeOfCallService.ReceiveTypeOfCallServiceClient ser = new ReceiveTypeOfCallService.ReceiveTypeOfCallServiceClient();

                ser.SaveOrUpdateCompleted += (object sender1, ReceiveTypeOfCallService.SaveOrUpdateCompletedEventArgs e1) =>
                {
                    if (JsonSerializerHelper.JsonToEntity<int>(e1.Result)>0)
                    {
                        Tools.ShowMessage("保存成功!", "", true);
                    }
                };

                string s = txtName.Text;
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(reciveType);

                ser.SaveOrUpdateAsync(json);//调用wcf异步保存

            }
            catch (Exception ex)
            {
                Tools.ShowMessage(ex.Message, "", false);
            }
        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            (this.Parent as RadWindow).Close();
        }
    }
}
